


#include <iostream>
#include <vector>
using namespace std;


class Solution
{
public:
    int minOperations(vector<int>& nums, int x)
    {
        int sz = nums.size();

        int goal = 0, cnt = 0;
        for (auto i : nums)
        {
            goal += i;
            if (i > x)
                cnt++;
        }
        if (cnt == sz || goal < x)
            return -1;

        goal -= x;

        int sum = 0, mincnt = sz + 1;
        for (int left = 0, right = 0; right < sz; ++right)
        {
            sum += nums[right];

            while (sum > goal)
            {
                sum -= nums[left++];
            }
            if (sum == goal)
                mincnt = min(mincnt, sz - right - 1 + left);
        }

        return mincnt == sz + 1 ? -1 : mincnt;
    }

    int totalFruit(vector<int>& f)
    {
        int sz = f.size();
        if (1 == sz)
            return sz;

        int maxlen = 0;
        int hash[100001] = { 0 }, kinds = 0;

        int left = 0, right = 0;
        while (right < sz)
        {
            if (0 == hash[f[right]])
            {
                ++kinds;
            }
            hash[f[right]]++;

            while (kinds > 2)
            {
                --hash[f[left]];
                if (0 == hash[f[left]])
                    --kinds;

                ++left;
            }
            maxlen = max(maxlen, right - left + 1);

            ++right;
        }

        return maxlen;
    }
};

void Test1(void)
{
    vector<int> v{ 1,3,7 };
    int x = 5;

    cout << Solution().minOperations(v, x) << endl;
}

#include <math.h>

void Test2(void)
{
    int n = 0;
    while (scanf("%d", &n) != EOF)
    {
        int base = 10, cnt = 0;
        for (int i = 0; i <= n; ++i)
        {
            int res = (int)pow(i, 2);

            if (i == base)
                base *= 10;

            if (res % base == i)
                ++cnt;
        }

        printf("%d", cnt);
    }
}

int main()
{
    //Test1();
    //Test2();


	return 0;
}